<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        //一、接收表单fore数据
        echo "hell0 adduser<br>";
        var_dump($_POST);
        echo "<br>";
        $uname=$_POST['username'];
        $password=$_POST['upwd'];
         $pwd=$_POST['uemail'];
        
      
        //二、处理表单数据，操作数据表并返回结果，操作数据表（插入、查询、删除、更新）
        //1.连接数据库
        $link=  mysqli_connect("localhost","root","");//创建一个数据库
        mysqli_select_db($link, "nhcar");//选择所查询的数据库
        mysqli_set_charset($link, "utf8");//设置字符集
        //2.写SQL语句，首先写SQL模板INSERI INTO users（uname\upwd\uemail)VALUES(‘abc’，‘123’，‘abc@123.com’）;
       $sql="insert into users(uname,upwd,uemail)values('$uname','$password','$pwd')";
        //3.执行查询返回结果，查询select，成功返回结果集，失败返回false，插入insert，更新update 删除delete，成功返回true，失败false
            $result=  mysqli_query($link, $sql);
            
//         exit();
       
         //三处理返回结果
         if($result){
             //header 页面跳转
//             header("Location:login.php");
            echo "<script>alert('注册成功！');location.href='login.php'</script>";
         }  else {
//             header("Location:register.php");
            echo "<script>alert('注册失败，请重新注册！');location.href='register.php'</script>";
         }
        ?>
    </body>
</html>
